new Vue({
    el: '#app',
    data() {
        return {
            headData:[{
                align:'center',
                type:'index',
                label:'序号',
                width:'50'
            },{
                align:'center',
                prop:'ID_Name',
                label:'村民姓名',
            },{
                align:'center',
                prop:'ID_Number',
                label:'身份证号',
            },{
                align:'center',
                prop:'Phone',
                label:'联系方式',
            },{
                align:'center',
                label:'地址',
                slot:[{
                    type:'key',
                    value:'Province'
                },{
                    type:'key',
                    value:'City'
                },{
                    type:'key',
                    value:'County'
                },{
                    type:'key',
                    value:'Village'
                },{
                    type:'key',
                    value:'Town'
                }]
            }],
            form: {
                SQLSerialNumber: "P_business_traceability_farmer",
                PaginationNumber: 1,//页数
                RowAmount: 20,//每页数据条数
                ID_Name:'',
                Condition: '',
                ExtensionCondition: '',
            },
            total: 0,
            tableData: [],	//表格数据
            loading: false,
        }
    },
    mounted() {
        $('title').text('村民管理');
        this.getList(this.form);//前端分页
    },
    methods: {
        onSerach() {			//查询方法
            this.form.PaginationNumber = 1;
            this.getList(this.form)
        },
        handleSizeChange(val) {
            this.form.PaginationNumber = 1;
            this.form.RowAmount = val;
            this.getList(this.form)
        },
        handleCurrentChange(val) {
            this.form.PaginationNumber = val;
            this.getList(this.form)
        },
        Add(){//添加
            window.location.href = 'add.html'
        },
        Edit(ID_Number){
            sessionStorage.setItem("ID_Number", ID_Number)
            window.location.href = 'edit.html?ID_Number='+ID_Number;
        },
        Remove(data){
            const that = this
            this.$confirm('警告！此操作将删除该村民, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                let row = deepClone(data);
                row.Row_Status = '1';
                $.ajax({
                    headers:requestHeaders(),
                    url: `${BASE_URL2}/generalBusiness/generalSave`,
                    type: 'POST',
                    data: {
                        Data: JSON.stringify({ 
                            Modify: { business_traceability_farmer: [row] } ,
                        })
                    },
                    success: function (res) {
                        if (res.Status === 'success') {
                            that.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            that.getList(that.form);
                        } else {
                            that.$message.error("删除失败，请稍后再试")
                        }
                    },
                    complete: function (XMLHttpRequest) {
                        that.loading = false;
                        requestPretreatment(XMLHttpRequest);
                    },
                    dataType: "json"
                })
            }).catch(() => {});
        },
        getList(form) {//换页方法
            const that = this
            let data = deepClone(form);
            data.Condition = window.btoa(unescape(encodeURIComponent("%"+data.ID_Name+"%")));
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
                type: 'POST',
                data,
                success: function (Result) {
                    that.tableData = Result.Rows;
                    that.total = Result.TotalRows;
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
    },
})